<html>
<head><meta charset="utf-8"><title>Replacing rustc_args_required_const with const generics · edition 2021 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/index.html">edition 2021</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html">Replacing rustc_args_required_const with const generics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226467858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226467858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226467858">(Feb 16 2021 at 03:43)</a>:</h4>
<p>Relevant issue: <a href="https://github.com/rust-lang/stdarch/issues/248">https://github.com/rust-lang/stdarch/issues/248</a></p>
<p><code>stdarch</code> exports many intrinsics that use <code>#[rustc_args_required_const]</code>, many of which are stable. In retrospect, this was a bad idea and we would like to switch these to use const generics instead. One of the main issues is that <code>#[rustc_args_required_const]</code> is effectively just a lint, which means that we still need a huge <code>match</code> within the function itself for every possible constant value the intrinsic can take. This is necessary because LLVM chokes on non-immediate values passed to certain intrinsics (particularly in unoptimized builds).</p>
<p>In <code>stdarch</code> we would like to replace this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[rustc_args_required_const(2)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">_mm_shuffle_ps</span><span class="p">(</span><span class="n">a</span>: <span class="nc">__m128</span><span class="p">,</span><span class="w"> </span><span class="n">b</span>: <span class="nc">__m128</span><span class="p">,</span><span class="w"> </span><span class="n">mask</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">__m128</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>With this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">_mm_shuffle_ps</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">mask</span>: <span class="kt">i32</span><span class="o">&gt;</span><span class="p">(</span><span class="n">a</span>: <span class="nc">__m128</span><span class="p">,</span><span class="w"> </span><span class="n">b</span>: <span class="nc">__m128</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">__m128</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This would allow us to remove the <code>match</code>es which were severely bloating the size of <code>libcore.rlib</code> to the point where it was having an impact on compile times.</p>
<p>The problem is that <code>_mm_shuffle_ps</code> is already stable. We can work around this by providing a backward-compatibility feature in the compiler which automatically turns <code>_mm_shuffle_ps(a, b, c)</code> into <code>_mm_shuffle_ps::&lt;{c}&gt;(a, b)</code>. This transition helper would be disabled in the 2021 edition, forcing everyone to switch to the new const generics syntax.</p>



<a name="226467923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226467923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226467923">(Feb 16 2021 at 03:44)</a>:</h4>
<blockquote>
<p>The problem is that _mm_shuffle_ps is already stable. We can work around this by providing a backward-compatibility feature in the compiler which automatically turns _mm_shuffle_ps(a, b, c) into _mm_shuffle_ps::&lt;{c}&gt;(a, b). This transition helper would be disabled in the 2021 edition, forcing everyone to switch to the new const generics syntax.</p>
</blockquote>
<p>This doesn't actually solve the build time problem. The standard library has to support all editions.</p>



<a name="226468010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468010">(Feb 16 2021 at 03:46)</a>:</h4>
<p>If the compiler can, for older editions, transparently rewrite the call to a const generic invocation at the AST/HIR level then we can use const generics even for functions that were previously stabilized.</p>



<a name="226468023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468023">(Feb 16 2021 at 03:47)</a>:</h4>
<p>oh I see, the plan is to make <code>rustc_args_required_const</code> even more magic than currently</p>



<a name="226468024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468024">(Feb 16 2021 at 03:47)</a>:</h4>
<p>that could work</p>



<a name="226468143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468143">(Feb 16 2021 at 03:49)</a>:</h4>
<p>However I have no idea how to go about actually implementing that in the compiler, or where in the pipeline it would fit in.</p>



<a name="226468217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468217">(Feb 16 2021 at 03:50)</a>:</h4>
<p>hmm, does <code>required_const</code> only take <code>const</code> arguments? Or could you pass in a value calculated at runtime?</p>



<a name="226468262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468262">(Feb 16 2021 at 03:51)</a>:</h4>
<p>The arguments have to be compile-time constants. This is currently checked by the compiler.</p>



<a name="226468286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468286">(Feb 16 2021 at 03:52)</a>:</h4>
<p>Ok, neat. You could probably start by adapting whatever checks that currently then.</p>



<a name="226468342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468342">(Feb 16 2021 at 03:52)</a>:</h4>
<p>(deleted)</p>



<a name="226468348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468348">(Feb 16 2021 at 03:52)</a>:</h4>
<p>oh booo zulip doesn't support <code>&lt;details&gt;</code></p>



<a name="226468350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468350">(Feb 16 2021 at 03:52)</a>:</h4>
<p>That check happens very late in MIR though. It is a hack based on the const promotion code.</p>



<a name="226468403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468403">(Feb 16 2021 at 03:54)</a>:</h4>
<p>Also the only potential issue is that <code>rustc_args_required_const</code> accepts constants derived from generic parameters, while const generics doesn't. I've been told that support for this is planned, but we would need to have it ready by the 2021 edition to avoid a breaking change.</p>



<a name="226468465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468465">(Feb 16 2021 at 03:54)</a>:</h4>
<p>another alternative is not to tie this to the edition</p>



<a name="226468472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468472">(Feb 16 2021 at 03:54)</a>:</h4>
<p>and deprecate the extra argument normally without removing it</p>



<a name="226468477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468477">(Feb 16 2021 at 03:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/268952-edition/topic/Replacing.20rustc_args_required_const.20with.20const.20generics/near/226468348">said</a>:</p>
<blockquote>
<p>oh booo zulip doesn't support <code>&lt;details&gt;</code></p>
</blockquote>
<div class="spoiler-block"><div class="spoiler-header">
<p>You can use spoiler instead</p>
</div><div class="spoiler-content" aria-hidden="true">
<p>See?</p>
</div></div>



<a name="226468483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468483">(Feb 16 2021 at 03:55)</a>:</h4>
<p>you can't do a hard break anyway since you need to support 2018 edition</p>



<a name="226468604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468604">(Feb 16 2021 at 03:57)</a>:</h4>
<p>that would let you rewrite this into a const argument whenever const generics get support for generic parameters</p>



<a name="226468612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468612">(Feb 16 2021 at 03:57)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[rustc_allow_legacy_call_syntax]</span><span class="w"> </span><span class="c1">// Only for 2018</span>
<span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">_mm_shuffle_ps</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">mask</span>: <span class="kt">i32</span><span class="o">&gt;</span><span class="p">(</span><span class="n">a</span>: <span class="nc">__m128</span><span class="p">,</span><span class="w"> </span><span class="n">b</span>: <span class="nc">__m128</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">__m128</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="c1">// Allowed in 2018, rejected in 2021</span>
<span class="n">_mm_shuffle_ps</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">,</span><span class="w"> </span><span class="mh">0xb</span><span class="p">);</span><span class="w"></span>

<span class="c1">// Allowed in both</span>
<span class="n">_mm_shuffle_ps</span>::<span class="o">&lt;</span><span class="mh">0xb</span><span class="o">&gt;</span><span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="w"> </span><span class="n">b</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="226468622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468622">(Feb 16 2021 at 03:57)</a>:</h4>
<p>But then we would have to support the legacy syntax forever.</p>



<a name="226468631"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468631" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468631">(Feb 16 2021 at 03:57)</a>:</h4>
<p>(which I guess we do anyways...)</p>



<a name="226468726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468726">(Feb 16 2021 at 03:59)</a>:</h4>
<p>that's not an argument to clean up the language definition for everyone who isn't rustc though</p>



<a name="226468743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468743">(Feb 16 2021 at 03:59)</a>:</h4>
<p>well, IMO it's an argument to only deprecate and not make it a hard error</p>



<a name="226468751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468751">(Feb 16 2021 at 03:59)</a>:</h4>
<p>because making it a hard error doesn't gain you anything</p>



<a name="226468817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468817">(Feb 16 2021 at 04:00)</a>:</h4>
<p>well the actual parsing of the code gets tricky, so I think that's a good reason to make it officially not in the language anymore</p>



<a name="226468825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468825">(Feb 16 2021 at 04:00)</a>:</h4>
<p>you've got two function arguments in the definition and three in the call site</p>



<a name="226468850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468850">(Feb 16 2021 at 04:01)</a>:</h4>
<p>sure, rustc has to support this forever but alternate rust compilers don't (for example), and neither does the langref</p>



<a name="226468890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468890">(Feb 16 2021 at 04:02)</a>:</h4>
<p>I don't see how that can be true? You can't just remove parts of the language</p>



<a name="226468938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468938">(Feb 16 2021 at 04:02)</a>:</h4>
<p>I mean that future compilers can support only &gt;= 2021, say</p>



<a name="226468945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468945">(Feb 16 2021 at 04:02)</a>:</h4>
<p>rustc can't but that's a rustc problem not a rust problem</p>



<a name="226468952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226468952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226468952">(Feb 16 2021 at 04:02)</a>:</h4>
<p>Oh. Well that seems to defeat the point of editions IMO.</p>



<a name="226469006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226469006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226469006">(Feb 16 2021 at 04:03)</a>:</h4>
<p>Also we really want to switch to const generics as soon as possible:</p>
<blockquote>
<p>On x86-64, stdarch contributes now 56 MB out of 76 MB of libcore.rlib size.</p>
</blockquote>



<a name="226469062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226469062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226469062">(Feb 16 2021 at 04:04)</a>:</h4>
<p>Does it? rustc is still there if you want to compile old code. But third party compilers don't have to have the same backward compatibility guarantees as rustc, and similarly for the language reference and other documentation of that sort, which can pretend that the latest version is the only version</p>



<a name="226469080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226469080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226469080">(Feb 16 2021 at 04:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/268952-edition/topic/Replacing.20rustc_args_required_const.20with.20const.20generics/near/226469006">said</a>:</p>
<blockquote>
<p>Also we really want to switch to const generics as soon as possible:</p>
<blockquote>
<p>On x86-64, stdarch contributes now 56 MB out of 76 MB of libcore.rlib size.</p>
</blockquote>
</blockquote>
<p>another alternative is to change this to use const generics unconditionally and do a crater run to see if it breaks any code in practice. If not, just document <code>rustc_const_required</code> as having the same semantics as const generics</p>



<a name="226469270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226469270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226469270">(Feb 16 2021 at 04:08)</a>:</h4>
<p>I think we can probably try this out today by changing the definition of <code>rustc_args_required_const</code> to reject values derived from generics.</p>



<a name="226469932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226469932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226469932">(Feb 16 2021 at 04:20)</a>:</h4>
<p>Anyways, the relevant question for 2021 edition planning is: should we forbid the legacy syntax in 2021 edition&gt;</p>



<a name="226472498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226472498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226472498">(Feb 16 2021 at 05:06)</a>:</h4>
<p>Yes, forbid the legacy syntax in 2021+ edition</p>



<a name="226492674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226492674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226492674">(Feb 16 2021 at 09:54)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="124288">@oli</span>, <span class="user-mention" data-user-id="216206">@lcnr</span></p>



<a name="226493047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493047">(Feb 16 2021 at 09:57)</a>:</h4>
<p>converting <code>rustc_args_required_const</code> to const generics should work. iirc we currently do this by explicitly promoting the last const argument which can capture variables from the outer scope or something? cc <span class="user-mention" data-user-id="120791">@RalfJ</span></p>



<a name="226493133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493133">(Feb 16 2021 at 09:58)</a>:</h4>
<p>so it might not be completely backwards compatible <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> even if the breakage is just theoretical</p>



<a name="226493192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493192">(Feb 16 2021 at 09:58)</a>:</h4>
<p>well... at some point we'll want to allow generics from the surrounding scope</p>



<a name="226493231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493231">(Feb 16 2021 at 09:59)</a>:</h4>
<p>yeah, but not variables</p>



<a name="226493258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493258">(Feb 16 2021 at 09:59)</a>:</h4>
<p>oh, don't worry about that, you can't capture variables in promoteds <span aria-label="grinning" class="emoji emoji-1f600" role="img" title="grinning">:grinning:</span></p>



<a name="226493264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493264">(Feb 16 2021 at 09:59)</a>:</h4>
<p>only if they are part of the expression</p>



<a name="226493303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493303">(Feb 16 2021 at 10:00)</a>:</h4>
<p>hmm <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> then i might be wrongly remembering this</p>



<a name="226493370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493370">(Feb 16 2021 at 10:00)</a>:</h4>
<p>you can promote <code>size_of</code> though, can you?</p>



<a name="226493389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493389">(Feb 16 2021 at 10:00)</a>:</h4>
<p>so that would break with that change (unless we make an even bigger hack)</p>



<a name="226493414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493414">(Feb 16 2021 at 10:00)</a>:</h4>
<p>ah, because it's an explicit promotion context</p>



<a name="226493416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493416">(Feb 16 2021 at 10:00)</a>:</h4>
<p>yea</p>



<a name="226493435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493435">(Feb 16 2021 at 10:00)</a>:</h4>
<p>damn, that thing biting us again</p>



<a name="226493469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493469">(Feb 16 2021 at 10:01)</a>:</h4>
<p>imo it's probably fine to just break that</p>



<a name="226493480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493480">(Feb 16 2021 at 10:01)</a>:</h4>
<p>agreed</p>



<a name="226493483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493483">(Feb 16 2021 at 10:01)</a>:</h4>
<p>i don't expect anyone to rely on it ^^</p>



<a name="226493493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493493">(Feb 16 2021 at 10:01)</a>:</h4>
<p>let's look at real world situtations first</p>



<a name="226493541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493541">(Feb 16 2021 at 10:01)</a>:</h4>
<p>so, it should be feasible</p>



<a name="226493778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493778">(Feb 16 2021 at 10:03)</a>:</h4>
<p>I don't think I will able to allocate the time and energy to work on an implementation here. Could review these changes though if someone else implements it</p>



<a name="226493787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493787">(Feb 16 2021 at 10:03)</a>:</h4>
<p>modulo implementation complexity</p>



<a name="226493807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493807">(Feb 16 2021 at 10:03)</a>:</h4>
<p>the hard part is rewriting calls</p>



<a name="226493958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226493958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226493958">(Feb 16 2021 at 10:04)</a>:</h4>
<p>so... even without those changes, there is some work to be done in parallel: create the new functions, deprecate the old ones in a way that we'll turn them off entirely in the new edition</p>



<a name="226495276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226495276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> isHavvy <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226495276">(Feb 16 2021 at 10:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/268952-edition/topic/Replacing.20rustc_args_required_const.20with.20const.20generics/near/226469062">said</a>:</p>
<blockquote>
<p>Does it? rustc is still there if you want to compile old code. But third party compilers don't have to have the same backward compatibility guarantees as rustc, and similarly for the language reference and other documentation of that sort, which can pretend that the latest version is the only version</p>
</blockquote>
<p>As it is defined today, to be a compiler for Rust 1.50, you have to support all editions. They are as much part of the language as anything else.</p>



<a name="226529778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226529778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226529778">(Feb 16 2021 at 15:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/268952-edition/topic/Replacing.20rustc_args_required_const.20with.20const.20generics/near/226493778">said</a>:</p>
<blockquote>
<p>I don't think I will able to allocate the time and energy to work on an implementation here. Could review these changes though if someone else implements it</p>
</blockquote>
<p>I'm happy to work on it but I need some guidance. At what stage in the compilation should the rewriting happen? AST/HIR/MIR?</p>



<a name="226529894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226529894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226529894">(Feb 16 2021 at 15:49)</a>:</h4>
<p>Currently <code>#[rustc_args_required_const]</code> doesn't actually rewrite anything, it's effectively just a lint that asserts the argument is a constant expression.</p>



<a name="226530426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226530426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226530426">(Feb 16 2021 at 15:52)</a>:</h4>
<p>it does actually rewrite the MIR</p>



<a name="226530466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226530466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226530466">(Feb 16 2021 at 15:53)</a>:</h4>
<p>the argument becomes an anonymous constant that is evaluated at compile-time</p>



<a name="226534456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226534456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226534456">(Feb 16 2021 at 16:12)</a>:</h4>
<p>I feel that the rewrite needs to happen earlier, when function parameter checking happens. Since we are trying to pass 3 arguments to a function that only takes 2 + 1 const generic.</p>



<a name="226534993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226534993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226534993">(Feb 16 2021 at 16:16)</a>:</h4>
<p>right, just stating what it is doing right now. Step 0 would probably be to change the attribute into a proc macro attribute that "just" rewrites the tokens of the function to be of the style that we want (with the attribute (or a modified version of it) left on the function, so that the call sites can query the attribute and rewrite the call).</p>



<a name="226535197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535197">(Feb 16 2021 at 16:17)</a>:</h4>
<p>I was actually thinking of hacking rustfmt into doing the rewrite for me.</p>



<a name="226535201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535201">(Feb 16 2021 at 16:17)</a>:</h4>
<p>the actual change at the call sites probably needs to happen in AST -&gt; HIR lowering, so that typeck and similar work (or does argument count checking happen during name resolution?)</p>



<a name="226535260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535260">(Feb 16 2021 at 16:17)</a>:</h4>
<p>The argument check happens in typeck, I just checked.</p>



<a name="226535265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535265">(Feb 16 2021 at 16:18)</a>:</h4>
<p>Can you elaborate on that? I don't know how rustfmt relates</p>



<a name="226535431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535431">(Feb 16 2021 at 16:18)</a>:</h4>
<p>I would modify rustfmt to detect the attribute and rewrite the function into const-generic form. The modifications to rustfmt would only be in my local copy, they won't be committed.</p>



<a name="226535522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535522">(Feb 16 2021 at 16:19)</a>:</h4>
<p>oh right, we can just change the actual source of all the functions</p>



<a name="226535565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535565">(Feb 16 2021 at 16:19)</a>:</h4>
<p>ok, I was thinking we'd just touch the attribute for now and leave the source code untouched</p>



<a name="226535724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535724">(Feb 16 2021 at 16:20)</a>:</h4>
<p>but... that works, too, I guess. At the next stdsimd sync we'll also need to do the change to the call site rewrites in rustc at the same time then</p>



<a name="226535733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535733">(Feb 16 2021 at 16:20)</a>:</h4>
<p>Actually I was thinking of introducing a separate attribute for this <code>#[rustc_magic_const_generic_call]</code>, so we can do the other changes incrementally.</p>



<a name="226535831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535831">(Feb 16 2021 at 16:21)</a>:</h4>
<p>yea, good point, that can be done independently</p>



<a name="226535832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535832">(Feb 16 2021 at 16:21)</a>:</h4>
<p><code>#[rustc_args_required_const]</code> isn't changed, and is eventually removed later.</p>



<a name="226535915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535915">(Feb 16 2021 at 16:21)</a>:</h4>
<p>ok, that plan sounds good to me, so <code>rustc_magic_const_generic_call</code> is the first order of business?</p>



<a name="226535978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226535978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226535978">(Feb 16 2021 at 16:21)</a>:</h4>
<p>Yep. I'll have a look at the AST lowering code to see how it could fit in.</p>



<a name="226536077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226536077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226536077">(Feb 16 2021 at 16:22)</a>:</h4>
<p>you'll need to have numbers like in <code>rustc_args_required_const</code> so you know which args to remap</p>



<a name="226536183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226536183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226536183">(Feb 16 2021 at 16:23)</a>:</h4>
<p>but since there are no methods with <code>rustc_args_required_const</code> afaik, you should be able to just touch the <code>ExprKind::Call</code> lowering and nothing else</p>



<a name="226549803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/226549803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#226549803">(Feb 16 2021 at 17:51)</a>:</h4>
<p>I thought the plan was to change <code>rustc_args_required_const</code> to create an inline const during some pre-MIR lowering step, e.g. to rewrite <code>foo(a,b,3+1)</code> to <code>foo(a,b,const{3+1})</code>? Then we could just kill the relevant part of promotion, since the argument would already be a const on the MIR level.<br>
Using const generics seems like an orthogonal second step to me.</p>



<a name="227056542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227056542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227056542">(Feb 20 2021 at 01:59)</a>:</h4>
<p>@oli How can I access the attributes on a <code>DefId</code> from AST lowering? Normally I would use <code>tcx.get_attrs(def_id)</code> but this isn't available in AST lowering.</p>



<a name="227057398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227057398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227057398">(Feb 20 2021 at 02:13)</a>:</h4>
<p>I would expect the node you're lowering to directly have the attributes somewhere on it, rather than needing to go through the tcx</p>



<a name="227057921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227057921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227057921">(Feb 20 2021 at 02:22)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I'm lowering an <code>ExprKind::Call</code> and want to look at the attributes on the <code>fn</code> that is being called.</p>



<a name="227057960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227057960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227057960">(Feb 20 2021 at 02:23)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(rustc_attrs)]</span><span class="w"></span>

<span class="cp">#[rustc_legacy_const_generics(0)]</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">X</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">X</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="fm">println!</span><span class="p">(</span><span class="s">"{}"</span><span class="p">,</span><span class="w"> </span><span class="n">foo</span><span class="p">(</span><span class="mi">0</span><span class="p">));</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="227058036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058036">(Feb 20 2021 at 02:25)</a>:</h4>
<p>hm, you'd need to access name resolution - I think? I'm not very familiar with this code, but I would assume that's necessary</p>



<a name="227058115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058115">(Feb 20 2021 at 02:26)</a>:</h4>
<p>aha</p>



<a name="227058140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058140">(Feb 20 2021 at 02:26)</a>:</h4>
<p>so it sounds like you can likely access that via self.resolver</p>



<a name="227058257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058257">(Feb 20 2021 at 02:28)</a>:</h4>
<p>and presumably get_partial_res on that with the nodeid from the Expr in the function call expr kind</p>



<a name="227058395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058395">(Feb 20 2021 at 02:30)</a>:</h4>
<p>ah no I think that's the wrong direction</p>



<a name="227058406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058406">(Feb 20 2021 at 02:30)</a>:</h4>
<p>if you lower the expr first, as is done today, that'll get you the hir path which is better</p>



<a name="227058437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058437">(Feb 20 2021 at 02:31)</a>:</h4>
<p>I can extract the <code>DefId</code> of the <code>fn</code> from the hir path already.</p>



<a name="227058451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058451">(Feb 20 2021 at 02:31)</a>:</h4>
<p>yeah that's what I just discovered</p>



<a name="227058454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058454">(Feb 20 2021 at 02:31)</a>:</h4>
<p>I'm just not sure how I can get to the attributes on that <code>DefId</code>.</p>



<a name="227058581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058581">(Feb 20 2021 at 02:33)</a>:</h4>
<p>hm, so in theory if you're in the same crate they're available via the hir</p>



<a name="227058586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058586">(Feb 20 2021 at 02:33)</a>:</h4>
<p>but the defid might be from a different crate, in which case you'd need to go through the crate store</p>



<a name="227058702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058702">(Feb 20 2021 at 02:35)</a>:</h4>
<p>Probably <span class="user-mention" data-user-id="124288">@oli</span> can help better than I, sorry</p>



<a name="227058752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058752">(Feb 20 2021 at 02:36)</a>:</h4>
<p>In practice the <code>DefId</code> is always going to refer to a function in <code>core::arch</code>.</p>



<a name="227058772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058772">(Feb 20 2021 at 02:36)</a>:</h4>
<p>So I do need this to work across crates :/</p>



<a name="227058826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058826">(Feb 20 2021 at 02:37)</a>:</h4>
<p>right, yeah, I think it's definitely possible (we've already resolved it so the crate is loaded and such)</p>



<a name="227058836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058836">(Feb 20 2021 at 02:37)</a>:</h4>
<p>but I'm not immediately seeing a nice way of getting that out</p>



<a name="227058905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227058905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227058905">(Feb 20 2021 at 02:38)</a>:</h4>
<p>I'm thinking I might need to add a method to <code>ResolverAstLowering</code>..</p>



<a name="227059132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059132">(Feb 20 2021 at 02:43)</a>:</h4>
<p>yeah that feels right to me, though a bit unfortunate from a separation perspective</p>



<a name="227059293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059293">(Feb 20 2021 at 02:46)</a>:</h4>
<p>and currently item attrs are only accessible from foreign crates via the query - it's technically likely relatively costly to decode them here too</p>



<a name="227059541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059541">(Feb 20 2021 at 02:50)</a>:</h4>
<p>Rather unfortunate considering I'd need to do this for every single <code>ExprKind::Call</code> lowering...</p>



<a name="227059571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059571">(Feb 20 2021 at 02:51)</a>:</h4>
<p>Right, yeah - I imagine it might be worthwhile to store a bitset or some more compact form specifically for this attribute</p>



<a name="227059652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059652">(Feb 20 2021 at 02:52)</a>:</h4>
<p>I would probably start with threading the cstore through and calling cdata.get_item_attrs(def_id.index, tcx.sess) on the right crate data; see examples in compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs which are for when you have a tcx already</p>



<a name="227059658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227059658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227059658">(Feb 20 2021 at 02:53)</a>:</h4>
<p>and we can check benchmarks</p>



<a name="227085694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227085694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227085694">(Feb 20 2021 at 11:33)</a>:</h4>
<p>yea, we can always make it efficient later, there are many ways to do that. The alternatives to modding lowering are unfortunately not great. We could fix up the call argument list checks and then do the transformation during MIR lowering, but all that feels like we'd be playing with fire as there'd be lots of code that could make the wrong assumptions</p>



<a name="227468350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227468350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227468350">(Feb 23 2021 at 17:20)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> <a href="https://github.com/rust-lang/rust/issues/82447">#82447</a> has an initial implementation, but it only works if the function definition is in a different crate than the function call. I'm having a bit of trouble figuring out how to recover attributes for an item in the crate that is currently being lowered. It's not a big deal since in practice we only care about cross-crate calls, so maybe we could just leave this unimplemented.</p>



<a name="227469985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227469985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227469985">(Feb 23 2021 at 17:31)</a>:</h4>
<p>Wow, great to see progress on this. Only today I was testing inlining, and recorded following as top functions being MIR inlined in core:</p>
<div class="codehilite"><pre><span></span><code>   4515 &lt;x86::__m512i as x86::m512iExt&gt;::as_m512i
   2978 &lt;x86::__m128 as x86::m128Ext&gt;::as_m128
   2978 &lt;Self as x86::m128Ext&gt;::as_f32x4
   2962 &lt;x86::__m128d as x86::m128dExt&gt;::as_m128d
   2962 &lt;Self as x86::m128dExt&gt;::as_f64x2
   2800 &lt;x86::__m512d as x86::m512dExt&gt;::as_m512d
   ...
</code></pre></div>



<a name="227477637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227477637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227477637">(Feb 23 2021 at 18:17)</a>:</h4>
<blockquote>
<p>I'm having a bit of trouble figuring out how to recover attributes for an item in the crate that is currently being lowered. </p>
</blockquote>
<p>Does <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.get_attrs">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.get_attrs</a> work?</p>



<a name="227477705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227477705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227477705">(Feb 23 2021 at 18:17)</a>:</h4>
<p>There is no tcx yet in AST lowering.</p>



<a name="227477793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227477793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227477793">(Feb 23 2021 at 18:17)</a>:</h4>
<p>oh I see this happens very early</p>



<a name="227478300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227478300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227478300">(Feb 23 2021 at 18:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics/near/227477637">said</a>:</p>
<blockquote>
<blockquote>
<p>I'm having a bit of trouble figuring out how to recover attributes for an item in the crate that is currently being lowered. </p>
</blockquote>
<p>Does <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.get_attrs">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.get_attrs</a> work?</p>
</blockquote>
<p>Once <a href="https://github.com/rust-lang/rust/issues/79519">#79519</a> lands, there will be a <code>HirId -&gt; &amp;[Attribute]</code>map constructed during lowering. By registering the attribute early enough, the attributes for the current item will be accessible.</p>



<a name="227478933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227478933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227478933">(Feb 23 2021 at 18:25)</a>:</h4>
<p>Actually AST lowering isn't even early enough: late resolution happens before AST lowering and needs to be aware of the rewrite since the expression in the <code>AnonConst</code> needs to be resolved inside a <code>ConstantItemRibKind</code>.</p>



<a name="227479198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/Replacing%20rustc_args_required_const%20with%20const%20generics/near/227479198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/Replacing.20rustc_args_required_const.20with.20const.20generics.html#227479198">(Feb 23 2021 at 18:26)</a>:</h4>
<p>This is needed to reject local variables passed in for the constant arg.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>